
package com.wyzz.hr.action;

import java.util.*;
import org.apache.axis.utils.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.base.TreeNode;
import com.wyzz.hr.bo.IDepartmentBO;
import com.wyzz.hr.bo.IJobTitleBo;
import com.wyzz.hr.bo.IOuperfcriteriaBo;
import com.wyzz.hr.bo.IOuresponseBo;
import com.wyzz.hr.bo.IPositionBaseBo;
import com.wyzz.hr.bo.IPositionBo;
import com.wyzz.hr.bo.ISysLogBO;
import com.wyzz.hr.pojo.Department;
import com.wyzz.hr.pojo.Depthist;
import com.wyzz.hr.pojo.Ouperfcriteria;
import com.wyzz.hr.pojo.Ouresponse;
import com.wyzz.hr.pojo.Position;
import com.wyzz.hr.pojo.PositionBase;
import com.wyzz.hr.pojo.PositionBaseHist;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.Message;
import com.wyzz.hr.util.StringUtil;
import com.wyzz.hr.util.SysConfigManager;

public class OrgDeptManageAction extends BaseAction {

	public OrgDeptManageAction() {
		msgNoAuth = "\u6CA1\u6709\u6743\u9650\uFF01";
		msgSaveSucc = "\u4FDD\u5B58\u6210\u529F\uFF01";
		msgDataStatuserror = "\u6570\u636E\u9519\u8BEF\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5\uFF01";// 数据错误
		// ，
		// 请刷新页面后重试
		// ！
		msgRenameNameNotChange = "\u540D\u79F0\u672A\u53D1\u751F\u53D8\u5316\uFF01";
		msgRenameRepeatName = "\u5F53\u524D\u8282\u70B9\u4E0B\u5DF2\u7ECF\u5B58\u5728\u540D\u79F0\u4E3A{0}\u7684\u8282\u70B9\uFF01";
		msgDeptNotExist = "{0}\u5DF2\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u8BD5\uFF01";
		msgDeptRepeatName = "\u5F53\u524D\u8282\u70B9\u4E0B\u5DF2\u7ECF\u5B58\u5728\u540D\u79F0\u4E3A{0}\u7684\u8282\u70B9\uFF01";
		msgMoveRootError = "\u4E0D\u80FD\u79FB\u52A8\u6839\u8282\u70B9\uFF01";
		msgMoveSameNodeError = "\u4E24\u8282\u70B9\u4E3A\u540C\u4E00\u8282\u70B9\uFF01";
		msgMoveAlreadyError = "\u8282\u70B9{0}\u5DF2\u7ECF\u5728\u8282\u70B9{1}\u4E0B\uFF01";
		msgMoveToSubError = "\u7236\u8282\u70B9\u4E0D\u80FD\u79FB\u52A8\u5230\u5176\u5B50\u7EA7\u8282\u70B9\uFF01";
		msgStartNoParent = "{0}\u65E0\u7236\u8282\u70B9\uFF0C\u4E0D\u80FD\u542F\u7528\uFF01";
		msgStartParentStop = "{0}\u7684\u7236\u8282\u70B9\u5DF2\u505C\u7528\uFF0C\u4E0D\u80FD\u542F\u7528\uFF01";
		msgMergeToSubError = "\u4E0D\u80FD\u5C06\u7236\u90E8\u95E8\u5408\u5E76\u5230\u5B50\u90E8\u95E8\uFF01";// 不能将父部门合并到子部门
		// ！
		nodeList = null;
		dept = null;
		nodeId = null;
		nodeType = null;
		jobtitleList = null;
		operateOver = null;
		rootId = null;
		disableRootId = null;
		deptResList = null;
		deptPBList = null;
		deptHistList = null;
		deptLogList = null;
		directSubDeptList = null;
		dbConfigManager = DatabaseSysConfigManager.getInstance();
	}

	public String execute() throws Exception {
		nodeList = getTreeNodesList();
		disableRootId = DISABLE_ROOT_ID;
		return "success";
	}

	public String goBranchDeptTabs() {
		return "branchDeptTabs";
	}

	public String editBranchDeptInit() throws Exception {
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		IJobTitleBo titleBo = (IJobTitleBo) SpringBeanFactory
				.getBean("jobTitleBo");
		setJobtitleList(titleBo.FindEnabledJobTitle());
		if (dept == null) {
			addErrorInfo(msgDataStatuserror);
			return null;
		}
		Department tempDept = null;
		if (!StringUtils.isEmpty(dept.getId())) {
			tempDept = deptBo.getDeptById(dept.getId());
			if (tempDept == null)
				return "error";
			getOtherInfoOfDept(tempDept);
			dept = tempDept;
		} else {
			dept.setDepartmentParentId(new Department(nodeId));
			dept.setDepartmentCate(Integer.valueOf(Integer.parseInt(nodeType)));
		}
		if (dept.getDepartmentCate().intValue() == 1
				|| dept.getDepartmentCate().intValue() == 0) {
			nodeType = "1";
			return "editBranchInit";
		}
		if (dept.getDepartmentCate().intValue() == 2) {
			nodeType = "2";
			return "editDeptInit";
		} else {
			return null;
		}
	}

	public String saveBranchDept() throws Exception {
		Map dbMap = dbConfigManager.getProperties();
		IPositionBo posBo = (IPositionBo) SpringBeanFactory
				.getBean("positionBo");
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		if (dept == null) {
			addErrorInfo(msgDataStatuserror);
			return "success";
		}
		Department tempDept = null;
		if (!StringUtils.isEmpty(dept.getId())) {
			tempDept = deptBo.loadDepartmentByNo(dept.getId(), new String[0]);
			if (tempDept == null) {
				addErrorInfo(StringUtil.message(msgDeptNotExist,
						new Object[] { dept.getDepartmentName() }));
				return "success";
			}
			if (StringUtils.isEmpty(dept.getDepartmentParentId().getId()))
				dept.setDepartmentParentId(null);
			deptBo.saveorUpdateDepartment(dept);
			operateOver = "editOver";
		} else {
			dept.setDepartmentName(dept.getDepartmentName().trim());
			Department sameNameDept = deptBo.getDeptByName(dept
					.getDepartmentName(), nodeId);
			if (sameNameDept != null) {
				addErrorInfo(StringUtil.message(msgDeptRepeatName,
						new Object[] { dept.getDepartmentName() }));
				operateOver = "nameRepeat";
				return "success";
			}
			dept.setId(getUUID());
			dept.setDepartmentStatus(new Integer(1));
			dept.setDepartmentSortId(deptBo.getMaxSortId());
			dept.setDepartmentCreateDate(new Date());
			Position parentRespPos = posBo.getRespPosOfDept(dept
					.getDepartmentParentId().getId());
			PositionBase respPB = dept.getRespPb();
			respPB.setId(getUUID());
			respPB.setPbDeptId(dept);
			respPB.setPbJobTitle(dept.getRespPb().getPbJobTitle());
			respPB.setPbInCharge(new Integer(1));
			respPB.setPbMaxEmployee(new Integer(1));
			respPB.setPbMaxExceed(Integer.valueOf(Integer.parseInt(dbMap
					.get("sys.position.max.exceed") == null ? "1"
					: (String) dbMap.get("sys.position.max.exceed"))));
			respPB.setPbSortId(pbBo.getMaxSortId());
			respPB.setPbStatus(new Integer(1));
			respPB.setPbSupId(parentRespPos.getPositionPbId());
			Position pos = new Position(getUUID());
			pos.setPositionPbId(respPB);
			pos.setPositionParentId(parentRespPos);
			pos.setPositionTakeNum(new Integer(1));
			pos.setPositionEmpNo(dept.getDeptHead());
			Depthist deptHist = new Depthist(getUUID(), dept, dept
					.getDepartmentParentId(), dept.getDepartmentName(),
					new Integer(1), new Date());
			PositionBaseHist pbHist = new PositionBaseHist(getUUID(), respPB,
					dept, respPB.getPbStatus(), respPB.getPbMaxEmployee(),
					respPB.getPbInCharge(), new Date(), null);
			boolean save = deptBo.addDeptSave(dept, respPB, pos, deptHist,
					pbHist);
			if (save)
				addSuccessInfo(StringUtil.message(msgSaveSucc, new Object[0]));
			operateOver = "newOver";
		}
		return "success";
	}

	public String deptRename(String deptId, String deptName) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		deptName = deptName.trim();
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		Department dept = deptBo.getDeptById(deptId);
		if (deptName != null && deptName.equals(dept.getDepartmentName()))
			return StringUtil.message(msgRenameNameNotChange, new Object[0]);
		if (dept.getDepartmentParentId() != null) {
			Department sameNameDept = deptBo.getDeptByName(deptName, dept
					.getDepartmentParentId().getId());
			if (sameNameDept != null)
				return StringUtil.message(msgRenameRepeatName,
						new Object[] { deptName });
		}
		dept.setDepartmentName(deptName);
		if (dept.getDepartmentCreateDate() == null)
			dept.setDepartmentCreateDate(new Date());
		deptBo.saveProcessDeptRename(dept);
		return "SUCC";
	}

	public String moveNode(String fromId, String toId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		List nodeList = getTreeNodesList();
		TreeNode fromNode = getNodeById(nodeList, fromId);
		TreeNode toNode = getNodeById(nodeList, toId);
		String info = moveNodeCheck(nodeList, fromNode, toNode);
		if (!"SUCC".equals(info)) {
			return info;
		} else {
			deptBo.saveDeptMove(fromId, toId);
			return "SUCC";
		}
	}

	public String moveNodeCheck(List nodeList, TreeNode fromNode,
			TreeNode toNode) {
		String info = "SUCC";
		if (fromNode.getNodeType() == 0)
			return StringUtil.message(msgMoveRootError, new Object[0]);
		if (fromNode.getNodeId().equals(toNode.getNodeId()))
			return StringUtil.message(msgMoveSameNodeError, new Object[0]);
		if (fromNode.getNodeParentId().equals(toNode.getNodeId()))
			return StringUtil.message(msgMoveAlreadyError, new Object[] {
					fromNode.getNodeName(), toNode.getNodeName() });
		TreeNode tempToNode = toNode;
		do {
			if ("0".equals(tempToNode.getNodeParentId()))
				break;
			tempToNode = getNodeById(nodeList, tempToNode.getNodeParentId());
			if (tempToNode.getNodeId().equals(fromNode.getNodeId()))
				info = StringUtil.message(msgMoveToSubError, new Object[0]);
		} while (true);
		return info;
	}

	public String disableDept(String deptId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		Department dept = deptBo.getDeptById(deptId);
		if (dept == null || dept.getDepartmentStatus().intValue() == 0)
			return StringUtil.message(msgDataStatuserror, new Object[0]);
		Message msg = new Message(null, "SUCC");
		try {
			deptBo.update_disableDept(deptId, msg);
		} catch (RuntimeException e) {
			if (!"SUCC".equals(msg.getMsgContent())) {
				return msg.getMsgContent();
			} else {
				e.printStackTrace();
				return e.getMessage();
			}
		}
		return "SUCC";
	}

	public String enableDept(String deptId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		Department dept = deptBo.getDeptById(deptId);
		if (dept == null || dept.getDepartmentStatus().intValue() == 1)
			return StringUtil.message(msgDataStatuserror, new Object[0]);
		String tempInfo = enableDeptCheck(dept);
		if (!"SUCC".equals(tempInfo))
			return tempInfo;
		tempInfo = deptBo.update_enableDept(deptId);
		if (!"SUCC".equals(tempInfo))
			return tempInfo;
		else
			return (new StringBuilder()).append("SUCC,").append(
					dept.getDepartmentParentId().getId()).toString();
	}

	public String enableDeptCheck(Department dept) {
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		List deptList = deptBo.FindAllDepartment();
		Department tempParentDept = getDeptById(dept.getDepartmentParentId()
				.getId(), deptList);
		if (tempParentDept == null)
			return StringUtil.message(msgStartNoParent, new Object[] { dept
					.getDepartmentName() });
		for (; tempParentDept.getDepartmentParentId() != null
				&& !StringUtils.isEmpty(tempParentDept.getDepartmentParentId()
						.getId()); tempParentDept = getDeptById(tempParentDept
				.getDepartmentParentId().getId(), deptList))
			if (tempParentDept.getDepartmentStatus().intValue() == 0)
				return StringUtil.message(msgStartParentStop,
						new Object[] { dept.getDepartmentName() });

		return "SUCC";
	}

	public Department getDeptById(String deptId, List deptList) {
		for (int i = 0; deptList != null && i < deptList.size(); i++) {
			Department dept = (Department) deptList.get(i);
			if (deptId.equals(dept.getId()))
				return dept;
		}

		return null;
	}

	public String deleteDept(String deptId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		Department dept = deptBo.getDeptById(deptId);
		if (dept == null)
			return StringUtil.message(msgDataStatuserror, new Object[0]);
		Message msg = new Message(null, "SUCC");
		try {
			deptBo.deleteDept(deptId, msg);
		} catch (RuntimeException e) {
			if (!"SUCC".equals(msg.getMsgContent())) {
				return msg.getMsgContent();
			} else {
				e.printStackTrace();
				return e.getMessage();
			}
		}
		return "SUCC";
	}

	public Object mergeNode(String fromId, String toId, String fromPBInfo) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		if (fromPBInfo.indexOf("#") < 0)
			return StringUtil.message(msgDataStatuserror, new Object[0]);
		String infoArr[] = fromPBInfo.split("#");
		String infoTwoArr[][] = new String[infoArr.length][6];
		for (int i = 0; infoArr != null && i < infoArr.length; i++) {
			String tempArr[] = infoArr[i].split(",");
			if (tempArr[0] == null || "".equals(tempArr[0].trim()))
				return StringUtil.message(msgDataStatuserror, new Object[0]);
			infoTwoArr[i] = tempArr;
		}

		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		Message msg = new Message(null, "SUCC");
		try {
			deptBo.saveMergeDept(fromId, toId, infoTwoArr, msg);
		} catch (RuntimeException e) {
			if (!"SUCC".equals(msg.getMsgContent())) {
				return msg.getMsgContent();
			} else {
				e.printStackTrace();
				return e.getMessage();
			}
		}
		return getTreeNodesList();
	}

	private List getTreeNodesList() {
		IDepartmentBO deptbo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		if (nodeList == null || nodeList.size() == 0)
			nodeList = new ArrayList();
		List deptList = deptbo.FindAllDepartment();
		TreeNode node;
		for (Iterator i$ = deptList.iterator(); i$.hasNext(); nodeList
				.add(node)) {
			Department dept = (Department) i$.next();
			if (dept.getDepartmentParentId() == null) {
				dept.setDepartmentParentId(new Department("0"));
				rootId = dept.getId();
			}
			node = null;
			if (dept.getDepartmentStatus().intValue() == 1) {
				node = new TreeNode(dept.getId(), dept.getDepartmentName(),
						dept.getDepartmentParentId().getId(), dept
								.getDepartmentCate().intValue(), dept
								.getDepartmentStatus().intValue());
				continue;
			}
			if (dept.getDepartmentStatus().intValue() == 0)
				node = new TreeNode(dept.getId(), dept.getDepartmentName(),
						DISABLE_ROOT_ID, dept.getDepartmentCate().intValue(),
						dept.getDepartmentStatus().intValue());
		}

		nodeList.add(new TreeNode("disabled",
				"\u505C\u7528\u7684\u7EC4\u7EC7\u7ED3\u6784", "0", 11));// 停用的组织结构
		return nodeList;
	}

	public List getAllEnabledDept(String fromType, String nodeId) {
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		List enabledDeptNodeList = deptBo.FindEnabledDepartmentNode();
		return enabledDeptNodeList;
	}

	public Object getAllPBofDept(String fromDeptIds, String toDeptId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth))
			return StringUtil.message(msgNoAuth, new Object[0]);
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		String info = "SUCC";
		String fromDeptArray[] = fromDeptIds.split(",");
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		String subDepts[] = deptBo.getAllSubDeptIds(fromDeptArray);
		int i = 0;
		do {
			if (subDepts == null || i >= subDepts.length)
				break;
			String dept = subDepts[i];
			if (dept.equals(toDeptId)) {
				info = (new StringBuilder()).append(info).append(
						StringUtil.message(msgMergeToSubError, new Object[0]))
						.toString();
				break;
			}
			i++;
		} while (true);
		if (!"SUCC".equals(info))
			return info.replace("SUCC", "");
		Map toPBMap = new HashMap();
		Map pbOperateMap = new HashMap();
		setMapValue(toPBMap, pbOperateMap, toDeptId);
		List pbList = pbBo.getAllPbsOfDept(fromDeptArray);
		for (i = 0; pbList != null && i < pbList.size(); i++) {
			PositionBase pb = (PositionBase) pbList.get(i);
			pb.setPbOperateMap(pbOperateMap);
			pb.setPbMoveToMap(toPBMap);
		}

		return pbList;
	}

	private void setMapValue(Map toPBMap, Map pbOperateMap, String toDeptId) {
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		List toPBList = pbBo.getAllPbsOfDept(new String[] { toDeptId });
		for (int i = 0; toPBList != null && i < toPBList.size(); i++) {
			PositionBase pb = (PositionBase) toPBList.get(i);
			toPBMap.put(pb.getId(), pb.getPbName());
		}

		pbOperateMap.put("0_1", "\u8BF7\u9009\u62E9");// 请选择
		pbOperateMap.put("1", "\u62F7\u8D1D");// 拷贝
		pbOperateMap.put("2", "\u5E76\u5165");// 并入
	}

	public void getOtherInfoOfDept(Department tempDept) {
		if (tempDept == null)
			return;
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		IPositionBo posBo = (IPositionBo) SpringBeanFactory
				.getBean("positionBo");
		PositionBase respPB = pbBo.getRespPBofDept(tempDept.getId());
		tempDept.setRespPb(respPB);
		Position respPos = posBo.getRespPosOfDept(tempDept.getId());
		tempDept.setDeptHead(respPos == null ? null : respPos
				.getPositionEmpNo());
		if (tempDept.getDepartmentStatus().intValue() == 1) {
			tempDept.setOrderNum(Integer.valueOf(deptBo.getOrderEmpNos(tempDept
					.getId())));
			tempDept.setActualNum(Integer.valueOf(deptBo
					.getActiveEmpNos(tempDept.getId())));
		}
		List subDeptList = deptBo.getSubDeptsByParentId(dept.getId());
		tempDept.setSubDeptList(subDeptList);
	}

	public String goDeptResTab() {
		IOuresponseBo deptResBo = (IOuresponseBo) SpringBeanFactory
				.getBean("ouresponseBo");
		if (dept != null && !StringUtils.isEmpty(dept.getId()))
			deptResList = deptResBo.getDeptRespLisByDept(dept.getId());
		return "success";
	}

	public String goDeptPerfcrTab() {
		IOuperfcriteriaBo perfcrBo = (IOuperfcriteriaBo) SpringBeanFactory
				.getBean("ouperfcriteriaBo");
		deptPerfcrList = perfcrBo.getDeptPerfcriteria(dept.getId());
		return "success";
	}

	public Ouresponse saveDeptRes(Ouresponse deptRes) {
		IOuresponseBo deptResBo = (IOuresponseBo) SpringBeanFactory
				.getBean("ouresponseBo");
		deptResBo.saveDeptRes(deptRes);
		return deptRes;
	}

	public Ouperfcriteria saveDeptPerfcr(Ouperfcriteria deptPerfcr) {
		IOuperfcriteriaBo perfcrBo = (IOuperfcriteriaBo) SpringBeanFactory
				.getBean("ouperfcriteriaBo");
		if (StringUtils.isEmpty(deptPerfcr.getId()))
			perfcrBo.addPbPerfcr(deptPerfcr);
		else
			perfcrBo.updatePbPerfcr(deptPerfcr);
		return deptPerfcr;
	}

	public String deleteDeptRes(String deptResId) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth)) {
			return StringUtil.message(msgNoAuth, new Object[0]);
		} else {
			IOuresponseBo deptResBo = (IOuresponseBo) SpringBeanFactory
					.getBean("ouresponseBo");
			deptResBo.deleteDeptResById(deptResId);
			return "SUCC";
		}
	}

	public String deleteDeptPerfcr(String id) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth)) {
			return StringUtil.message(msgNoAuth, new Object[0]);
		} else {
			IOuperfcriteriaBo perfcrBo = (IOuperfcriteriaBo) SpringBeanFactory
					.getBean("ouperfcriteriaBo");
			perfcrBo.delPbPerfcr(id);
			return "SUCC";
		}
	}

	public String saveDeptResSortBatch(String ids[]) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth)) {
			return StringUtil.message(msgNoAuth, new Object[0]);
		} else {
			IOuresponseBo deptResBo = (IOuresponseBo) SpringBeanFactory
					.getBean("ouresponseBo");
			deptResBo.saveSortIdBatch(ids);
			return "SUCC";
		}
	}

	public String saveDeptPerfcrSortBatch(String ids[]) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth)) {
			return StringUtil.message(msgNoAuth, new Object[0]);
		} else {
			IOuperfcriteriaBo perfcrBo = (IOuperfcriteriaBo) SpringBeanFactory
					.getBean("ouperfcriteriaBo");
			perfcrBo.savePbPerfcrOrder(ids);
			return "SUCC";
		}
	}

	public String goDeptPBsTab() {
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		if (dept != null && !StringUtils.isEmpty(dept.getId()))
			deptPBList = pbBo.getAllPbsOfDept(new String[] { dept.getId() });
		return "success";
	}

	public String goDeptHistTab() {
		ISysLogBO logBO = (ISysLogBO) SpringBeanFactory.getBean("logBO");
		if (dept != null && !StringUtils.isEmpty(dept.getId()))
			deptLogList = logBO.getLogs("department", dept.getId());
		return "success";
	}

	public String goDirectSubDeptTab() {
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		if (this.dept != null && !StringUtils.isEmpty(this.dept.getId())) {
			directSubDeptList = deptBo.getSubDeptsByParentId(this.dept.getId());
			for (int i = 0; directSubDeptList != null
					&& i < directSubDeptList.size(); i++) {
				Department dept = (Department) directSubDeptList.get(i);
				getOtherInfoOfDept(dept);
			}

		}
		return "success";
	}

	public String saveDeptOrder(String ids[]) {
		String auth = DWRUtil.checkAuth("OrgDeptManage", "execute");
		if (!"ADM".equals(auth)) {
			return StringUtil.message(msgNoAuth, new Object[0]);
		} else {
			IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
					.getBean("departmentBO");
			deptBo.saveDeptOrder(ids);
			return "SUCC";
		}
	}

	private String getUUID() {
		UUID uuid = UUID.randomUUID();
		return uuid.toString();
	}

	public TreeNode getNodeById(List nodeList, String nodeId) {
		TreeNode node = null;
		Iterator i$ = nodeList.iterator();
		do {
			if (!i$.hasNext())
				break;
			TreeNode temp = (TreeNode) i$.next();
			if (!temp.getNodeId().equals(nodeId))
				continue;
			node = temp;
			break;
		} while (true);
		return node;
	}

	public Department getDept() {
		return dept;
	}

	public void setDept(Department dept) {
		this.dept = dept;
	}

	public String getNodeType() {
		return nodeType;
	}

	public void setNodeType(String nodeType) {
		this.nodeType = nodeType;
	}

	public List getJobtitleList() {
		return jobtitleList;
	}

	public void setJobtitleList(List jobtitleList) {
		this.jobtitleList = jobtitleList;
	}

	public List getNodeList() {
		return nodeList;
	}

	public void setNodeList(List nodeList) {
		this.nodeList = nodeList;
	}

	public String getNodeId() {
		return nodeId;
	}

	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}

	public String getOperateOver() {
		return operateOver;
	}

	public void setOperateOver(String operateOver) {
		this.operateOver = operateOver;
	}

	public String getRootId() {
		return rootId;
	}

	public void setRootId(String rootId) {
		this.rootId = rootId;
	}

	public String getDisableRootId() {
		return disableRootId;
	}

	public void setDisableRootId(String disableRootId) {
		this.disableRootId = disableRootId;
	}

	public List getDeptResList() {
		return deptResList;
	}

	public void setDeptResList(List deptResList) {
		this.deptResList = deptResList;
	}

	public List getDeptPBList() {
		return deptPBList;
	}

	public void setDeptPBList(List deptPBList) {
		this.deptPBList = deptPBList;
	}

	public List getDeptHistList() {
		return deptHistList;
	}

	public void setDeptHistList(List deptHistList) {
		this.deptHistList = deptHistList;
	}

	public List getDeptLogList() {
		return deptLogList;
	}

	public void setDeptLogList(List deptLogList) {
		this.deptLogList = deptLogList;
	}

	public List getDeptPerfcrList() {
		return deptPerfcrList;
	}

	public void setDeptPerfcrList(List deptPerfcrList) {
		this.deptPerfcrList = deptPerfcrList;
	}

	public List getDirectSubDeptList() {
		return directSubDeptList;
	}

	public void setDirectSubDeptList(List directSubDeptList) {
		this.directSubDeptList = directSubDeptList;
	}

	private String msgNoAuth;
	private String msgSaveSucc;
	private String msgDataStatuserror;
	private String msgRenameNameNotChange;
	private String msgRenameRepeatName;
	private String msgDeptNotExist;
	private String msgDeptRepeatName;
	private String msgMoveRootError;
	private String msgMoveSameNodeError;
	private String msgMoveAlreadyError;
	private String msgMoveToSubError;
	private String msgStartNoParent;
	private String msgStartParentStop;
	private String msgMergeToSubError;
	private static String DISABLE_ROOT_ID = "disabled";
	private List nodeList;
	private Department dept;
	private String nodeId;
	private String nodeType;
	private List jobtitleList;
	private String operateOver;
	private String rootId;
	private String disableRootId;
	private List deptResList;
	private List deptPBList;
	private List deptPerfcrList;
	private List deptHistList;
	private List deptLogList;
	private List directSubDeptList;
	SysConfigManager dbConfigManager;

}
